using UnityEngine;

public class TGS_PlayerTank_Script : MonoBehaviour
{
    [Header("移动速度")]
    public float moveSpeed = 6f;
    [Header("转向速度")]
    public float turnSpeed = 360f;
    [Header("炮弹预设体")]
    public GameObject bulletPrefab;
    [Header("炮弹飞行速度")]
    public float bulletSpeed = 100f;
    
    private float hor, ver;
    private bool fire;
    Transform firePoint;
    void Awake()
    {
        firePoint = transform.Find("Top/Gun/FirePoint");
    }

    void Update()
    {
        hor = Input.GetAxis("Horizontal");
        ver = Input.GetAxis("Vertical");
        // 前后移动
        transform.position += transform.forward * ver * Time.deltaTime * moveSpeed;
        // 左右转向
        transform.eulerAngles += transform.up * hor * Time.deltaTime * turnSpeed;
        // 发射炮弹
        if (Input.GetKeyDown(KeyCode.V))
        {
            // 生成炮弹
            GameObject bullet = Instantiate(bulletPrefab, firePoint.position, Quaternion.identity);
            // 给炮弹加上速度
            bullet.GetComponent<Rigidbody>().velocity = transform.forward * bulletSpeed;
            // 在1s后销毁炮弹
            Destroy(bullet, 1);
        }
    }
}
